﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiC3DGeneratorForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

internal class CUiC3DGeneratorForm : TxForm
{
  private const string REGISTRY_FORM_NAME = "Create3Documentation";
  private const string REGISTRY_LEVELS_MENU = "LevelsMenu";
  private const string REGISTRY_STEPS_FIRST_COLUMN_WIDTH = "StepsFirstColumnWidth";
  private const string REGISTRY_STEPS_SECOND_COLUMN_WIDTH = "StepsSecondColumnWidth";
  private const string REGISTRY_SPLITTER_WIDTH = "SplitterWidth";
  private CApC3DManagerApp m_generatorApp;
  private List<CApC3DProcessNodeData> m_nodeOperationsList;
  private ToolStripItem m_selectedLevelMenu;
  private IContainer components;
  private GroupBox m_processTreeGroup;
  private GroupBox m_stepListGroup;
  private Button m_moveSelectionToSteps;
  private Button m_removeSelectedSteps;
  private Button m_removeAllSteps;
  private CUiC3DProcessesGrid m_processTree;
  private Label m_stepOrderLabel;
  private CUiC3DStepsGrid m_stepList;
  private Button m_generate;
  private Button m_cancel;
  private CUiC3DSplitButton m_moveByLevelsToSteps;
  private ContextMenuStrip m_levelsContextMenu;
  private ToolStripMenuItem m_level1Menu;
  private ToolStripMenuItem m_level2Menu;
  private ToolStripMenuItem m_level3Menu;
  private Button m_buttonSettings;
  private Panel panelMiddleButtons;
  private SplitContainer splitContainerTop;

  internal CUiC3DGeneratorForm(CApC3DManagerApp generatorApp)
  {
    this.InitializeComponent();
    this.m_generatorApp = generatorApp;
  }

  private void CUiC3DGeneratorForm_Load(object sender, EventArgs e)
  {
    this.m_nodeOperationsList = this.m_generatorApp.GetProcesses();
    this.m_processTree.Initialize(ref this.m_nodeOperationsList);
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiC3DGeneratorForm_FormClosing);
    this.m_stepList.ListUpdated += new CUiC3DStepsGrid.CUiC3DStepsGrid_ListUpdatedEventHandler(this.m_stepList_ListUpdated);
    this.m_stepList.Initialize(ref this.m_generatorApp);
    this.RestoreUISetting();
    this.m_moveSelectionToSteps.Enabled = false;
    this.m_removeSelectedSteps.Enabled = false;
    this.EnableGenerateButton();
    this.VerticallyCenterMiddleButtons();
  }

  private void CUiC3DGeneratorForm_FormClosing(object sender, FormClosingEventArgs e)
  {
    foreach (CApC3DProcessNodeData nodeOperations in this.m_nodeOperationsList)
      nodeOperations.Dispose();
  }

  private void m_moveByLevelsToSteps_Click(object sender, EventArgs e)
  {
    this.MoveToSteps(this.GetSelectedMenuItem(this.m_levelsContextMenu.Items));
  }

  private void m_moveSelectionToSteps_Click(object sender, EventArgs e) => this.MoveToSteps(-1);

  private void m_removeSelectedSteps_Click(object sender, EventArgs e)
  {
    this.m_generatorApp.RemoveSteps(this.m_stepList.RemoveSelectedSteps());
    this.m_processTree.RefreshAllRowsStyle();
    this.EnableRemoveStepButton();
    this.EnableGenerateButton();
  }

  private void m_removeAllSteps_Click(object sender, EventArgs e)
  {
    this.m_generatorApp.RemoveSteps(this.m_stepList.RemoveAllSteps());
    this.m_processTree.RefreshAllRowsStyle();
    this.EnableRemoveStepButton();
    this.EnableGenerateButton();
  }

  private void m_generate_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this.StoreUISetting();
    try
    {
      if (!this.m_generatorApp.StartGeneration(((RowColCollection) ((C1FlexGridBase) this.m_stepList).Rows).Count - ((RowColCollection) ((C1FlexGridBase) this.m_stepList).Rows).Fixed, (Form) this))
        return;
      int num = (int) TxMessageBox.Show(CApC3DUtils.GetResourceManager().GetString("CREATE_3D_DOCUMENTATION_SUCCESS_MSG"), CApC3DUtils.GetResourceManager().GetString("CREATE_3D_DOCUMENTATION_CMD_NAME"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
      ((Form) this).Close();
    }
    finally
    {
      Cursor.Current = current;
    }
  }

  private void m_cancel_Click(object sender, EventArgs e)
  {
    this.StoreUISetting();
    ((Form) this).Close();
  }

  private void levelMenu_Click(object sender, EventArgs e)
  {
    this.m_selectedLevelMenu = (ToolStripItem) sender;
    foreach (ToolStripMenuItem toolStripMenuItem in (ArrangedElementCollection) this.m_levelsContextMenu.Items)
    {
      if (toolStripMenuItem != this.m_selectedLevelMenu)
        toolStripMenuItem.Checked = false;
    }
  }

  private void m_buttonSettings_Click(object sender, EventArgs e)
  {
    CUiC3DGeneratorSettingsForm dgeneratorSettingsForm = new CUiC3DGeneratorSettingsForm();
    dgeneratorSettingsForm.DocumentationSettings = this.m_generatorApp.DocumentationSettings;
    if (((Form) dgeneratorSettingsForm).ShowDialog() != DialogResult.OK)
      return;
    this.m_generatorApp.DocumentationSettings = dgeneratorSettingsForm.DocumentationSettings;
  }

  private void m_processTree_AfterSelChange(object sender, RangeEventArgs e)
  {
    this.EnableMoveToStepButton();
  }

  private void m_stepList_AfterSelChange(object sender, RangeEventArgs e)
  {
    this.EnableRemoveStepButton();
  }

  private void m_stepList_ListUpdated(object sender, EventArgs args) => this.EnableGenerateButton();

  private void panelMiddleButtons_Resize(object sender, EventArgs e)
  {
    this.VerticallyCenterMiddleButtons();
  }

  private void RestoreUISetting()
  {
    int index = 0;
    object s1;
    TxFormSettings.RestoreFormValue((Form) this, "Create3Documentation", "LevelsMenu", ref s1);
    if (s1 != null)
      index = int.Parse(s1 as string);
    if (index < 0 || index >= this.m_levelsContextMenu.Items.Count)
      index = 0;
    if (this.m_levelsContextMenu.Items[index] is ToolStripMenuItem toolStripMenuItem)
      toolStripMenuItem.Checked = true;
    object s2;
    TxFormSettings.RestoreFormValue((Form) this, "Create3Documentation", "StepsFirstColumnWidth", ref s2);
    if (s2 != null)
      this.m_stepList.StepColumnWidth = int.Parse(s2 as string);
    TxFormSettings.RestoreFormValue((Form) this, "Create3Documentation", "StepsSecondColumnWidth", ref s2);
    if (s2 != null)
      this.m_stepList.SnapshotColumnWidth = int.Parse(s2 as string);
    object s3;
    TxFormSettings.RestoreFormValue((Form) this, "Create3Documentation", "SplitterWidth", ref s3);
    if (s3 == null)
      return;
    this.splitContainerTop.SplitterDistance = int.Parse(s3 as string);
  }

  private void StoreUISetting()
  {
    TxFormSettings.StoreFormValue((Form) this, "Create3Documentation", "LevelsMenu", this.GetSelectedMenuItem(this.m_levelsContextMenu.Items).ToString());
    TxFormSettings.StoreFormValue((Form) this, "Create3Documentation", "StepsFirstColumnWidth", this.m_stepList.StepColumnWidth.ToString());
    TxFormSettings.StoreFormValue((Form) this, "Create3Documentation", "StepsSecondColumnWidth", this.m_stepList.SnapshotColumnWidth.ToString());
    TxFormSettings.StoreFormValue((Form) this, "Create3Documentation", "SplitterWidth", this.splitContainerTop.SplitterDistance.ToString());
  }

  private int GetSelectedMenuItem(ToolStripItemCollection menuItems)
  {
    int selectedMenuItem = -1;
    int num = 0;
    foreach (ToolStripMenuItem menuItem in (ArrangedElementCollection) menuItems)
    {
      if (menuItem.Checked)
      {
        selectedMenuItem = num;
        break;
      }
      ++num;
    }
    return selectedMenuItem;
  }

  private void MoveToSteps(int level)
  {
    this.m_generatorApp.ProcessesToSteps(this.m_processTree.GetProcesses(level));
    this.m_stepList.UpdateStepList();
    this.m_processTree.RefreshAllRowsStyle();
    this.EnableGenerateButton();
  }

  private void EnableGenerateButton() => this.m_generate.Enabled = this.m_stepList.DoesListValid();

  private void EnableMoveToStepButton()
  {
    this.m_moveSelectionToSteps.Enabled = ((RowColCollection) ((C1FlexGridBase) this.m_processTree).Rows.Selected).Count > 0;
  }

  private void EnableRemoveStepButton()
  {
    this.m_removeSelectedSteps.Enabled = ((RowColCollection) ((C1FlexGridBase) this.m_stepList).Rows.Selected).Count > 0;
  }

  private void VerticallyCenterMiddleButtons()
  {
    int num1 = (this.panelMiddleButtons.Height - (this.m_removeAllSteps.Top + this.m_removeAllSteps.Height - this.m_moveByLevelsToSteps.Top)) / 2;
    int num2 = this.m_moveSelectionToSteps.Top - (this.m_moveByLevelsToSteps.Top + this.m_moveByLevelsToSteps.Height);
    this.m_moveByLevelsToSteps.Top = num1;
    this.m_moveSelectionToSteps.Top = this.m_moveByLevelsToSteps.Top + this.m_moveByLevelsToSteps.Height + num2;
    this.m_removeSelectedSteps.Top = this.m_moveSelectionToSteps.Top + this.m_moveSelectionToSteps.Height + num2;
    this.m_removeAllSteps.Top = this.m_removeSelectedSteps.Top + this.m_removeSelectedSteps.Height + num2;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.components = (IContainer) new Container();
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiC3DGeneratorForm));
    this.m_processTreeGroup = new GroupBox();
    this.m_stepListGroup = new GroupBox();
    this.m_stepOrderLabel = new Label();
    this.m_processTree = new CUiC3DProcessesGrid(this.components);
    this.m_stepList = new CUiC3DStepsGrid(this.components);
    this.m_moveSelectionToSteps = new Button();
    this.m_removeSelectedSteps = new Button();
    this.m_removeAllSteps = new Button();
    this.m_generate = new Button();
    this.m_cancel = new Button();
    this.m_levelsContextMenu = new ContextMenuStrip(this.components);
    this.m_level1Menu = new ToolStripMenuItem();
    this.m_level2Menu = new ToolStripMenuItem();
    this.m_level3Menu = new ToolStripMenuItem();
    this.m_moveByLevelsToSteps = new CUiC3DSplitButton();
    this.m_buttonSettings = new Button();
    this.panelMiddleButtons = new Panel();
    this.splitContainerTop = new SplitContainer();
    this.m_processTreeGroup.SuspendLayout();
    ((ISupportInitialize) this.m_processTree).BeginInit();
    this.m_stepListGroup.SuspendLayout();
    ((ISupportInitialize) this.m_stepList).BeginInit();
    this.m_levelsContextMenu.SuspendLayout();
    this.panelMiddleButtons.SuspendLayout();
    this.splitContainerTop.BeginInit();
    this.splitContainerTop.Panel1.SuspendLayout();
    this.splitContainerTop.Panel2.SuspendLayout();
    this.splitContainerTop.SuspendLayout();
    ((Control) this).SuspendLayout();
    this.m_processTreeGroup.Controls.Add((Control) this.m_processTree);
    componentResourceManager.ApplyResources((object) this.m_processTreeGroup, "m_processTreeGroup");
    this.m_processTreeGroup.Name = "m_processTreeGroup";
    this.m_processTreeGroup.TabStop = false;
    ((C1FlexGridBase) this.m_processTree).AllowDragging = (AllowDraggingEnum) 3;
    ((C1FlexGridBase) this.m_processTree).AllowEditing = false;
    ((C1FlexGridBase) this.m_processTree).AllowSorting = (AllowSortingEnum) 0;
    componentResourceManager.ApplyResources((object) this.m_processTree, "m_processTree");
    ((C1FlexGridBase) this.m_processTree).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_processTree).HighLight = (HighLightEnum) 0;
    ((Control) this.m_processTree).Name = "m_processTree";
    ((RowColCollection) ((C1FlexGridBase) this.m_processTree).Rows).Count = 1;
    ((C1FlexGridBase) this.m_processTree).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_processTree).StyleInfo = componentResourceManager.GetString("m_processTree.StyleInfo");
    ((C1FlexGridBase) this.m_processTree).Tree.Column = 0;
    ((C1FlexGridBase) this.m_processTree).AfterSelChange += new RangeEventHandler(this.m_processTree_AfterSelChange);
    this.m_stepListGroup.Controls.Add((Control) this.m_stepList);
    this.m_stepListGroup.Controls.Add((Control) this.m_stepOrderLabel);
    componentResourceManager.ApplyResources((object) this.m_stepListGroup, "m_stepListGroup");
    this.m_stepListGroup.Name = "m_stepListGroup";
    this.m_stepListGroup.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_stepOrderLabel, "m_stepOrderLabel");
    this.m_stepOrderLabel.Name = "m_stepOrderLabel";
    ((C1FlexGridBase) this.m_stepList).AllowDragging = (AllowDraggingEnum) 3;
    ((C1FlexGridBase) this.m_stepList).AllowSorting = (AllowSortingEnum) 0;
    componentResourceManager.ApplyResources((object) this.m_stepList, "m_stepList");
    ((C1FlexGridBase) this.m_stepList).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_stepList).HighLight = (HighLightEnum) 0;
    ((Control) this.m_stepList).Name = "m_stepList";
    ((RowColCollection) ((C1FlexGridBase) this.m_stepList).Rows).Count = 1;
    ((C1FlexGridBase) this.m_stepList).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_stepList).StyleInfo = componentResourceManager.GetString("m_stepList.StyleInfo");
    ((C1FlexGridBase) this.m_stepList).AfterSelChange += new RangeEventHandler(this.m_stepList_AfterSelChange);
    componentResourceManager.ApplyResources((object) this.m_moveSelectionToSteps, "m_moveSelectionToSteps");
    this.m_moveSelectionToSteps.Name = "m_moveSelectionToSteps";
    this.m_moveSelectionToSteps.UseVisualStyleBackColor = true;
    this.m_moveSelectionToSteps.Click += new EventHandler(this.m_moveSelectionToSteps_Click);
    componentResourceManager.ApplyResources((object) this.m_removeSelectedSteps, "m_removeSelectedSteps");
    this.m_removeSelectedSteps.Name = "m_removeSelectedSteps";
    this.m_removeSelectedSteps.UseVisualStyleBackColor = true;
    this.m_removeSelectedSteps.Click += new EventHandler(this.m_removeSelectedSteps_Click);
    componentResourceManager.ApplyResources((object) this.m_removeAllSteps, "m_removeAllSteps");
    this.m_removeAllSteps.Name = "m_removeAllSteps";
    this.m_removeAllSteps.UseVisualStyleBackColor = true;
    this.m_removeAllSteps.Click += new EventHandler(this.m_removeAllSteps_Click);
    componentResourceManager.ApplyResources((object) this.m_generate, "m_generate");
    this.m_generate.DialogResult = DialogResult.OK;
    this.m_generate.Name = "m_generate";
    this.m_generate.UseVisualStyleBackColor = true;
    this.m_generate.Click += new EventHandler(this.m_generate_Click);
    componentResourceManager.ApplyResources((object) this.m_cancel, "m_cancel");
    this.m_cancel.DialogResult = DialogResult.Cancel;
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    this.m_levelsContextMenu.Items.AddRange(new ToolStripItem[3]
    {
      (ToolStripItem) this.m_level1Menu,
      (ToolStripItem) this.m_level2Menu,
      (ToolStripItem) this.m_level3Menu
    });
    this.m_levelsContextMenu.Name = "contextMenuStrip1";
    this.m_levelsContextMenu.ShowCheckMargin = true;
    this.m_levelsContextMenu.ShowImageMargin = false;
    componentResourceManager.ApplyResources((object) this.m_levelsContextMenu, "m_levelsContextMenu");
    this.m_level1Menu.CheckOnClick = true;
    this.m_level1Menu.Name = "m_level1Menu";
    componentResourceManager.ApplyResources((object) this.m_level1Menu, "m_level1Menu");
    this.m_level1Menu.Click += new EventHandler(this.levelMenu_Click);
    this.m_level2Menu.CheckOnClick = true;
    this.m_level2Menu.Name = "m_level2Menu";
    componentResourceManager.ApplyResources((object) this.m_level2Menu, "m_level2Menu");
    this.m_level2Menu.Click += new EventHandler(this.levelMenu_Click);
    this.m_level3Menu.CheckOnClick = true;
    this.m_level3Menu.Name = "m_level3Menu";
    componentResourceManager.ApplyResources((object) this.m_level3Menu, "m_level3Menu");
    this.m_level3Menu.Click += new EventHandler(this.levelMenu_Click);
    componentResourceManager.ApplyResources((object) this.m_moveByLevelsToSteps, "m_moveByLevelsToSteps");
    this.m_moveByLevelsToSteps.ContextMenuStrip = this.m_levelsContextMenu;
    this.m_moveByLevelsToSteps.Image = (Image) StringTable.levels;
    this.m_moveByLevelsToSteps.Name = "m_moveByLevelsToSteps";
    this.m_moveByLevelsToSteps.UseVisualStyleBackColor = true;
    this.m_moveByLevelsToSteps.Click += new EventHandler(this.m_moveByLevelsToSteps_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonSettings, "m_buttonSettings");
    this.m_buttonSettings.Name = "m_buttonSettings";
    this.m_buttonSettings.UseVisualStyleBackColor = true;
    this.m_buttonSettings.Click += new EventHandler(this.m_buttonSettings_Click);
    this.panelMiddleButtons.Controls.Add((Control) this.m_moveByLevelsToSteps);
    this.panelMiddleButtons.Controls.Add((Control) this.m_moveSelectionToSteps);
    this.panelMiddleButtons.Controls.Add((Control) this.m_removeAllSteps);
    this.panelMiddleButtons.Controls.Add((Control) this.m_removeSelectedSteps);
    componentResourceManager.ApplyResources((object) this.panelMiddleButtons, "panelMiddleButtons");
    this.panelMiddleButtons.Name = "panelMiddleButtons";
    this.panelMiddleButtons.Resize += new EventHandler(this.panelMiddleButtons_Resize);
    componentResourceManager.ApplyResources((object) this.splitContainerTop, "splitContainerTop");
    this.splitContainerTop.Name = "splitContainerTop";
    this.splitContainerTop.Panel1.Controls.Add((Control) this.m_processTreeGroup);
    this.splitContainerTop.Panel2.Controls.Add((Control) this.m_stepListGroup);
    this.splitContainerTop.Panel2.Controls.Add((Control) this.panelMiddleButtons);
    ((Form) this).AcceptButton = (IButtonControl) this.m_generate;
    ((ContainerControl) this).AutoScaleDimensions = new SizeF(6f, 13f);
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((Control) this).Controls.Add((Control) this.m_generate);
    ((Control) this).Controls.Add((Control) this.m_buttonSettings);
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Control) this).Controls.Add((Control) this.splitContainerTop);
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiC3DGeneratorForm);
    ((Form) this).Load += new EventHandler(this.CUiC3DGeneratorForm_Load);
    this.m_processTreeGroup.ResumeLayout(false);
    ((ISupportInitialize) this.m_processTree).EndInit();
    this.m_stepListGroup.ResumeLayout(false);
    this.m_stepListGroup.PerformLayout();
    ((ISupportInitialize) this.m_stepList).EndInit();
    this.m_levelsContextMenu.ResumeLayout(false);
    this.panelMiddleButtons.ResumeLayout(false);
    this.panelMiddleButtons.PerformLayout();
    this.splitContainerTop.Panel1.ResumeLayout(false);
    this.splitContainerTop.Panel2.ResumeLayout(false);
    this.splitContainerTop.EndInit();
    this.splitContainerTop.ResumeLayout(false);
    ((Control) this).ResumeLayout(false);
  }
}
